﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlarmClock
{
    public class CalculatorInt
    {
        public static int[] CalculateDeltaTime(DateTime timeOne, DateTime timeTwo)
        {
            int[] times;
            double time = (timeTwo - timeOne).TotalSeconds;
            int year = (int)(time / 31536000);
            int day = (int)((time % 31536000) / 86400);
            int hour = (int)(((time % 31536000) % 86400) / 3600);
            int minute = (int)((((time % 31536000) % 86400) % 3600) / 60);
            int second = (int)(time % 60);
            if (year > 0)
                times = new int[] { year, day, hour, minute, second };
            else
            {
                if (day > 0)
                    times = new int[] { day, hour, minute, second };
                else
                {
                    if (hour > 0)
                        times = new int[] { hour, minute, second };
                    else
                    {
                        if (minute > 0)
                            times = new int[] { minute, second };
                        else
                            times = new int[] { second };
                    }
                }
            }
            return times;
        }
    }
    public class CalculatorStr
    {
        public static String CalculateDeltaTime(DateTime timeOne, DateTime timeTwo)
        {
            String timeStr = "";
            double time = (timeTwo - timeOne).TotalSeconds;
            int year = (int)(time / 31536000);
            int day = (int)((time % 31536000) / 86400);
            int hour = (int)(((time % 31536000) % 86400) / 3600);
            int minute = (int)((((time % 31536000) % 86400) % 3600) / 60);
            int second = (int)(time % 60);
            if (year > 0)
                timeStr += year + "年" + day + "天" + hour + ":" + minute + ":" + second;
            else
            {
                if (day > 0)
                    timeStr += day + "天" + hour + ":" + minute + ":" + second;
                else
                {
                    if (hour > 0)
                        timeStr += hour + ":" + minute + ":" + second;
                    else
                    {
                        if (minute > 0)
                            timeStr += minute + ":" + second;
                        else
                        {
                            timeStr += second;
                        }
                    }
                }
            }
            return timeStr;
        }
    }
}
